home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Internet Info 1994 March
/
Internet Info CD-ROM (Walnut Creek) (March 1994).iso
/
networking
/
ip
/
ka9q
/
xobbs.arc
/
xodir.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-05-03
|
2KB
|
89 lines
/* XODIR.C Directory routines for XOBBS. Jim Durham, W2XO 10-24-88 */
/* Version 1.0 */
/* Code released to the amateur radio community */
#include "xobbs.h"
getdirc(fp) /*get chars from directory pipe, throwing away*/
FILE *fp; /* newlines*/
{
int c;
c=getc(fp);
if(c == '\n')
c=getc(fp);
return c;
}
getdirent(fp,s,t)
FILE *fp;
char *s,*t;
{
int c;
char *cp;
c=getdirc(fp); /*throw away blank*/
cp=s; /*point to first string*/
*cp='\0';
while((c=getdirc(fp)) != ' ')
*cp++=c;
*cp='\0';
cp=t;
*cp='\0';
while(((c=getdirc(fp)) != ',') && (c != EOF))
*cp++=c;
*cp='\0';
if(c==EOF)
return 0;
else
return 1;
}
dodir(path,mode)
char *path;
int mode;
{
FILE *fp;
char cmdstr[40],tempstr[10],temp2str[15];
int cnt,c,siz;
sprintf(cmdstr,"ls -sm %s",lowcase(path));
fp=popen(cmdstr,"r"); /*open the pipe from ls*/
while((c=getc(fp)) != EOF && c != ','); /*ratchet past the "Total xx" */
if(c == EOF) return;
cnt=0; /*set entries/line count to 0 */
for(;;){
if(getdirent(fp,tempstr,temp2str) == 0) break;
if(mode == 0)
sprintf(prinbuf,"|%-14s |",temp2str);
else{
siz = atoi(tempstr);
if(siz < 2)
siz = 2;
sprintf(prinbuf,"|%-14s %4dK| ",temp2str,siz/2);
}
prinout(NOFLUSH);
if(cnt++ == 2)
{
sprintf(prinbuf,"\n");
prinout(NOFLUSH);
cnt=0;
}
}
if(mode == 0)
sprintf(prinbuf,"|%-14s |\n",temp2str);
else{
siz = atoi(tempstr);
if(siz < 2)
siz = 2;
sprintf(prinbuf,"|%-14s %4dK| \n",temp2str,siz/2);
}
prinout(FLUSH);
pclose(fp);
}